﻿/*
 * $Id$
 */ 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace discoverter.DiscoverterWin
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            this.Text = string.Format("WSSv3/MOSS 2007/2010 Discoverter {0}.{1}.{2}", v.Major, v.Minor, v.Build);
        }

        /// <summary>
        /// Browse for the .disco File
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBrowseDisco_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter = "Disco Files|*.disco|All Files|*.*";
                ofd.Title = "Please select your .disco file";
                ofd.Multiselect = false;
                ofd.CheckFileExists = true;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    tbDiscoFile.Text = ofd.FileName;
                }
            }
        }

        /// <summary>
        /// Browse for the .wsdl File
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBrowseWsdl_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter = "WSDL Files|*.wsdl|All Files|*.*";
                ofd.Title = "Please select your .wsdl file";
                ofd.Multiselect = false;
                ofd.CheckFileExists = true;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    tbWsdlFile.Text = ofd.FileName;
                }
            }
        }

        /// <summary>
        /// Browse for the Output Directory
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBrowseOutput_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog fbd = new FolderBrowserDialog())
            {
                fbd.Description = "Select the directory where the created .aspx files should be written to:";
                fbd.ShowNewFolderButton = true;
                if (fbd.ShowDialog() == DialogResult.OK)
                {
                    tbOutputDirectory.Text = fbd.SelectedPath;
                }
            }
        }

        private void btnConvert_Click(object sender, EventArgs e)
        {
            try
            {
                Discoverter.ConvertServiceFiles(tbDiscoFile.Text, tbWsdlFile.Text, tbOutputDirectory.Text,rbSP14.Checked);
                MessageBox.Show("Files converted!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("There was an error when converting the files!\r\n{0}", ex.Message));
            }
        }
    }
}
